from django.contrib import admin

# Register your models here.
from django.contrib import admin
from .models import Permission, Role, UserInfo


class RoleAdmin(admin.ModelAdmin):
    list_display = ["title", "权限"]

    def 权限(self, obj):
        return [bt.title for bt in obj.permissions.all()]

    filter_horizontal = ('permissions',)


class UserInfoAdmin(admin.ModelAdmin):
    list_display = ["username", "角色", "status", "nickname", "signature", "last_login"]

    def 角色(self, obj):
        return [a.title for a in obj.roles.all()]

    filter_horizontal = ('roles',)


class PermissionAdmin(admin.ModelAdmin):
    list_display = ["title", "parent", "url", "topid", "icon", "status", "type"]


admin.site.register(Role, RoleAdmin)
admin.site.register(UserInfo, UserInfoAdmin)
admin.site.register(Permission, PermissionAdmin)
